﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using SmartSiteManagementSystem.IServices;
using SmartSiteManagementSystem.IRepository.User;
using SmartSiteManagementSystem.Models.User;
using System.Linq;

namespace SmartSiteManagementSystem.Services
{
    public class UserService:IUserService
    {
        private readonly IUserInfoRepository  _userInfoRepository;
        public UserService(IUserInfoRepository userInfoRepository)
        {
            _userInfoRepository = userInfoRepository;
        }

        public UserInfo GetUserInfoById(int id)
        {
            Hashtable param = new Hashtable();
            param.Add("user_id", id);
            return _userInfoRepository.Get(param);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public UserInfo GetUserInfoByLogin(string loginName) {
            Hashtable param = new Hashtable();
            param.Add("logon_name", loginName);
            param.Add("is_delete", 0);
            return _userInfoRepository.Get(param);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int GetUserInfoListCount(Hashtable param)
        {
            return _userInfoRepository.GetCount(param);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <param name="orderBy"></param>
        /// <param name="first"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        public IList<UserInfo> GetUserInfoList(Hashtable param, string orderBy, int first, int rows)
        {
            return _userInfoRepository.GetList(param, orderBy, first, rows);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="materialInfo"></param>
        /// <returns></returns>
        public bool UpdateUserInfo(UserInfo userInfo)
        {
            bool back = _userInfoRepository.Update(userInfo);
            return back;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int InsertUserInfo(UserInfo userInfo)
        {
            return _userInfoRepository.Insert(userInfo);
        }
    }
}
